package controller

import (
	"strconv"

	"device-admin/internal/app/web/service/devlog"

	"192.168.1.75/go-pkg/response"
	"github.com/gin-gonic/gin"
)

type Devlog struct{}

// EventLogList 异常事件记录
func (Devlog) DevEventLogList(c *gin.Context) {
	startTime, _ := strconv.ParseInt(c.Query("start_time"), 10, 64)
	endTime, _ := strconv.ParseInt(c.Query("end_time"), 10, 64)
	page, _ := strconv.ParseInt(c.Query("page"), 10, 64)
	limit, _ := strconv.ParseInt(c.Query("limit"), 10, 64)
	var level int64
	if levelQuery, exists := c.GetQuery("level"); !exists {
		level = -1
	} else {
		level, _ = strconv.ParseInt(levelQuery, 10, 64)
	}
	log, total := devlog.DevEventLogList(
		c.Query("robot_id"),
		startTime,
		endTime,
		int(level),
		int(page),
		int(limit),
	)
	response.JSON(c, map[string]interface{}{
		"list":  log,
		"total": total,
	}, nil)
}
